package com.hdq.controller.admin;

import com.hdq.result.PageResult;
import com.hdq.result.Result;
import com.hdq.service.NoticeService;
import dto.NoticeAddDTO;
import dto.NoticeEditDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/notice")
@Tag(name = "公告管理")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @PostMapping
    @Operation(summary = "新增公告")
    public Result insert(@RequestBody NoticeAddDTO noticeAddDTO) {
        noticeService.insert(noticeAddDTO);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "删除公告/批量删除")
    public Result delete(@RequestParam List<Long> ids) {
        noticeService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{page}")
    @Operation(summary = "分页查询公告")
    public Result<PageResult> selectByPage(@PathVariable Integer page, @RequestParam Integer pageSize) {
        PageResult list= noticeService.selectByPage(page,pageSize);
        return Result.success(list);
    }

    @PutMapping
    @Operation(summary = "更新公告")
    public Result update(@RequestBody NoticeEditDTO noticeEditDTO) {
      noticeService.update(noticeEditDTO);
        return Result.success();
    }

}
